<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=q54xW5I3uHC9g1MuXPV4r7yUANvybZYm"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=q54xW5I3uHC9g1MuXPV4r7yUANvybZYm"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }

        #allmap{
            height: 450px;
            width: 100%;
            overflow: hidden;
            font-family: "微软雅黑";
            border:1px solid green;
        }

        /*百度地图搜索框定位*/
        .tangram-suggestion-main {
            z-index: 999999;
        }
        /*设置弹出框样式*/
        .el-dialog__body {
            padding: 0px 20px;
            color: #606266;
            font-size: 14px;
        }
        /**/
        /*.el-input--suffix .el-input__inner {
            width: 450px;
        }*/
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>首页<small>公司分布图</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <template>
            <el-tabs v-model="activeName"  @tab-click="handleClick">
                <el-tab-pane label="分布图" name="first">
                    <div id="allmap"></div>
                    <div>
                        <button onclick='bdGEO()' class='btn'>批量解析</button>
                    </div>
                    <!--<iframe name="right" class="el-main" src="../bmaps/map.html" width="100%" height="580px" frameborder="0"></iframe>-->
                </el-tab-pane>

                <el-tab-pane label="详细信息" name="second">
                    <div class="filter-container">
                        <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="address" label="公司地址" align="center"></el-table-column>

                        <el-table-column prop="latitude" label="所在经度" align="center"></el-table-column>
                        <el-table-column prop="longitude" label="所在纬度" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
<!--                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>-->

                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                                class="pagiantion"
                                @current-change="handleCurrentChange"
                                :current-page="pagination.currentPage"
                                :page-size="pagination.pageSize"
                                layout="total, prev, pager, next, jumper"
                                :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增地址" :visible.sync="dialogFormVisible" @opened="createMap">

                            <div class="filter-container">
                                <el-input id="suggestId" name="address_detail" placeholder="请输入要查询的地址" v-model="address_detail"  style="width: 400px;"></el-input>
                                <el-button type="primary" @click="handleAdd()" class="butT">确定添加</el-button>
                            </div>
                            <!--                            地址：<input type="text" id="suggestId" name="address_detail" placeholder="请输入要查询的地址" v-model="address_detail" class="input_style">-->
                            <div style="width:400px;height:400px;border:#ccc solid 1px;" id="l-map"></div>
                        </el-dialog>
                    </div>
                </el-tab-pane>
            </el-tabs>
        </template>
    </div>
</div>
</body>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
            address_detail:'', //详细地址
            userlocation: {longitude: "", latitude: ""},
            adds:[]
        },
        mounted () {
        },
        created() {
            this.findPage();
            this.findAddress();
        },
        methods: {
            createMap(){
                // 百度地图API功能
                function G(id) {
                    return document.getElementById(id);
                }

                var map = new BMap.Map("l-map");
                map.centerAndZoom("北京",12);                   // 初始化地图,设置城市和地图级别。

                var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
                    {"input" : "suggestId"
                        ,"location" : map
                    });

                ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
                    var str = "";
                    var _value = e.fromitem.value;
                    var value = "";
                    if (e.fromitem.index > -1) {
                        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    }
                    str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

                    value = "";
                    if (e.toitem.index > -1) {
                        _value = e.toitem.value;
                        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    }
                    str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
                    G("searchResultPanel").innerHTML = str;
                });

                var myValue;
                ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
                    var _value = e.item.value;
                    myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

                    setPlace();
                });

                function setPlace(){
                    map.clearOverlays();    //清除地图上所有覆盖物
                    function myFun(){
                        var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
                        map.centerAndZoom(pp, 18);
                        map.addOverlay(new BMap.Marker(pp));    //添加标注
                    }
                    var local = new BMap.LocalSearch(map, { //智能搜索
                        onSearchComplete: myFun
                    });
                    local.search(myValue);
                }
            },
            // 重置表单
            resetForm() {

            },
            // 弹出添加窗口
            handleCreate() {
                //1.显示窗口
                this.dialogFormVisible =true;
            },
            // 弹出编辑窗口
            handleUpdate(row) {

            },
            //查询地址
            findAddress(){
                axios.post("/address/findAddress.do").then(res =>{
                    alert(res.data.data)
                    if(res.data.flag){
                        this.adds = res.data.data;
                    }
                })
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {

            },
            handleAdd(){

            },
            handleClick(tab, event) {
               
            }
        }
    });
</script>

</html>
<script>
    var adds = [
        "包河区金寨路1号（金寨路与望江西路交叉口）",
        "庐阳区凤台路209号（凤台路与蒙城北路交叉口）",
        "蜀山区金寨路217号(近安医附院公交车站)",
        "蜀山区梅山路10号(近安徽饭店) ",
        "蜀山区 长丰南路159号铜锣湾广场312室",
        "合肥市寿春路93号钱柜星乐町KTV（逍遥津公园对面）",
        "庐阳区长江中路177号",
        "新站区胜利路89"
    ];
    var map = new BMapGL.Map("allmap");
    map.centerAndZoom(new BMapGL.Point(117.269945,31.86713), 13);
    map.enableScrollWheelZoom(true);
    var myGeo = new BMapGL.Geocoder();
    var index = 0;


    function bdGEO(){
        if (index < adds.length) {
            var add = adds[index];
            geocodeSearch(add);
            index++;
        }
    }
    function geocodeSearch(add){
        myGeo.getPoint(add, function(point){
            if (point) {
                var address = new BMapGL.Point(point.lng, point.lat);
                addMarker(address,new BMapGL.Label(index+":"+add,{offset:new BMapGL.Size(10,-10)}));
            }
        }, "合肥市");
        bdGEO();
    }
    // 编写自定义函数,创建标注
    function addMarker(point,label){
        var marker = new BMapGL.Marker(point);
        map.addOverlay(marker);
        marker.setLabel(label);
    }
    for(){
        myGeo.getPoint(adds[i], function(point){
            if (point) {
                var address = new BMapGL.Point(point.lng, point.lat);
                addMarker(address,new BMapGL.Label(index+":"+add,{offset:new BMapGL.Size(10,-10)}));
            }
        }, "合肥市");
    }
</script>




